import { LOCAL_LANGUAGE_CACHE_KEY } from '@/constants'
import { LanguageEnum } from '@/enums/appEnum'
import { store } from '@/stores'
import { localStore } from '@/utils/cache/storage'
import { defineStore } from 'pinia'

/**
 * 定义应用状态管理
 */
export const useAppStore = defineStore('app', () => {
  // state
  const language = ref(localStore.get(LOCAL_LANGUAGE_CACHE_KEY) || LanguageEnum.ZH_CN) // 语言

  // 设置语言
  const setLanguage = (lang: LanguageEnum) => {
    language.value = lang
  }

  return {
    language,
    setLanguage
  }
})

// 需要在设置之外使用
export const useAppStoreWithOut = () => {
  return useAppStore(store)
}
